<!DOCTYPE html>
<html>
	<head>
		<title>Aline Princet Albums</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="fr"/>
		
		<link rel="stylesheet" type="text/css" href="css/upload.css" media="screen, projection" />
		
		<script language="JavaScript" type="text/javascript" src="Scripts/jsscript.js"></script>
		<script language="JavaScript" type="text/javascript" src="Scripts/swfobject.js"></script>
	</head>
	<body>
	<img id="homepage" src="../img/gui/debut.png" />
	<div id="content" style="">
	
		<?php
		if(isset($_POST['ressource']) && $_POST['ressource']!="") //Si $_GET['nom'] existe, on supprime le fichier...
		{
     
          $images=$_POST['ressource'];
          foreach ($images as $image){
          		$image_small=str_replace("large","small",$image);
          		if (file_exists($image) && file_exists($image_small)){
	          		unlink($image);
	          		unlink($image_small);
          		}
          	}
			$_POST['ressource']="";
		}
		$adresses = array("culinaire"=>"uploads/large/culinaire/",
							"natures_mortes"=>"uploads/large/natures_mortes/",
							"travaux_personnels"=>"uploads/large/travaux_personnels/",
							"parutions"=>"uploads/large/parutions/",); //Adresse du dossier.
		if (isset($_POST['choix_dossier']) && $_POST['choix_dossier']!=""){
			$menu=$_POST['choix_dossier'];
			
		}else{
			$menu="culinaire";
		}
		?>
		<div id="deleteZone" style="">
		<form id="form_delete" name="form_delete" method="post" action="">
		<?php 
		  echo '<fieldset><legend>Choix du dossier de destination</legend>'; 
		  $check='';
		  foreach ($adresses as $nom => $adresse) {
			if ($nom==$menu){
				$check='checked="checked"';
			}else {
				$check='';
			  }
		  	echo '<input '.$check.'  type="radio"  name="choix_dossier" value="'.$nom.'"  onchange="hide(this.value);">'.$nom;
		  }
		  echo '</fieldset>';
		?>
		
		
		<?php
			
			
			$image_largeur = 150;
			$valide_extensions = array('jpg','JPG', 'jpeg','JPEG', 'gif','GIF', 'png','PNG');
			$i=0;
			foreach ($adresses as $nom => $adresse) {
				$Ressource = opendir($adresse); 
				$i++;
				if ($nom==$menu){
					echo '<fieldset id="folder'.$i.'" style="display: block;"><legend>Liste des fichiers du dossier "'.$nom.'"</legend><br>'; //Ouverture de fieldset
				}else {
					echo '<fieldset id="folder'.$i.'" style="display: none;"><legend>Liste des fichiers du dossier "'.$nom.'"</legend><br>'; //Ouverture de fieldset
				}
			
				while($fichier = readdir($Ressource))
					{
					    $berk = array('.', '..');
					
					    $test_Fichier = $adresse.$fichier;
					
					    if(!in_array($fichier, $berk) && !is_dir($test_Fichier))
					    {
					        $ext = pathinfo($fichier,  PATHINFO_EXTENSION);
					
					        if(in_array($ext, $valide_extensions))
					        {
					            echo '
					                <div style="display:inline; width:150px; margin-right:10px">
					                    <input type="checkbox" name="ressource[]" value="'.$test_Fichier.'">
					                   <a href="'.$test_Fichier.'" target="blank"> <img src="'.$test_Fichier.'" style="width:150px;height:100px;" /></a>
					                </div>';
					        }
					    }
					}
				closedir($Ressource); //Fermeture du dossier. 
				echo '<br></fieldset>'; //Fermeture du fieldset.
			}
		?> 
		<input type="button" name="btnSubmit" value="lancer la suppression" id="btnSubmitSupp" onclick="supp();" >
		</form>
	</div>
		
	</div>
	<script type="text/javascript">
		function supp(){
			document.getElementById('form_delete').submit(); 
			return true;
		}
		function hide(folders){	
			document.getElementById('folder1').style.display="none";
			document.getElementById('folder2').style.display="none";
			document.getElementById('folder3').style.display="none";
			document.getElementById('folder4').style.display="none";
			folder=folders;
			if(folder=="natures_mortes"){
				document.getElementById('folder1').style.display='block';
			}
			if(folder=="culinaire"){
				document.getElementById('folder2').style.display='block';
			}
			if(folder=="travaux_personnels"){
				document.getElementById('folder3').style.display='block';
			}
			if(folder=="parutions"){
				document.getElementById('folder4').style.display='block';
			}
		}
	</script>	
	</body>
</html>